﻿
// ****************************************************************************** //
//  Utility module which gathers all constants being used in the other f# classe  //
//      Moreover, it has one method and some logic to guarantee the distance      //
//             coherence between the different screen resolutions.                //
// ****************************************************************************** //

module MapGrid

open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Input
open Microsoft.Xna.Framework.Graphics
open Utilities
open Casanova
open Coroutines
open Math
open SI

type WinBox =
  {
    mutable leftbound        : float32
    mutable rightbound       : float32
  }


//frog path X (horizontal movements)
let mutable road_x = [|-40.0f;-35.0f;-30.0f;-25.0f;-20.0f;-15.0f;-10.0f;-5.0f;0.0f;5.0f;10.0f;15.0f;20.0f;25.0f;30.0f;35.0f;40.0f|]

let SPAWNING_X = road_x.[0] + (-15.0f)

//left and right bounds (in tuples) to define the 5 boxes where the frog has to go to win the match
let mutable win_boxes = [|(-32.0f,-27.0f); (-17.0f,-12.0f); (-2.0f,3.0f); (13.0f,18.0f); (28.0f,33.0f)|]

let mutable  screen_ratio : float32 = 1.0f

//method to get screen resolution ratio
let getScreenRatio(ratio : float32) =
    screen_ratio <- (float32)ratio / 1.7786f
    road_x <- [|-40.0f * screen_ratio;-35.0f* screen_ratio;-30.0f* screen_ratio;-25.0f* screen_ratio;-20.0f* screen_ratio;-15.0f* screen_ratio;-10.0f* screen_ratio;-5.0f* screen_ratio;0.0f* screen_ratio;5.0f* screen_ratio;10.0f* screen_ratio;15.0f* screen_ratio;20.0f* screen_ratio;25.0f* screen_ratio;30.0f*screen_ratio;35.0f* screen_ratio;40.0f * screen_ratio|]
    win_boxes <- [|(-32.4f*screen_ratio,-27.4f*screen_ratio); (-17.2f*screen_ratio,-12.2f*screen_ratio); (-2.0f*screen_ratio,3.0f*screen_ratio); (13.2f*screen_ratio,18.2f*screen_ratio); (28.4f*screen_ratio,33.4f*screen_ratio)|]
        

//frog path Y (vertical movements)
//legenda:     start | car1 | car2 |car3|car4|sidewalk|riv1|riv2|riv3|riv4| finish
let road_y = [|-19.0f;-14.5f;-11.0f;-7.5f;-4.2f;-1.5f;2.0f;6.0f;9.5f;13.0f;16.0f |]

//frog path Z (vertical movements)
let road_z = [| 2.0f;1.0f;0.0f;-1.0f;-2.0f;-3.0f;-4.0f;-5.0f;-6.0f;-7.0f;-8.0f |]


// ****************************************************************************** //
//                                Game Constants                                  //
// ****************************************************************************** //

//starting positions
let INITIAL_X = road_x.[8]
let INITIAL_Y = road_y.[0]
let INITIAL_Z = road_z.[0]

let SIDEWALK_Y = road_y.[5]
let SIDEWALK_Z = road_z.[5]


//win vertical position
let WIN_Y = road_y.[10]
let WIN_Z = road_z.[10]

//vertical cars & river positions
let ROW1_Y = road_y.[4]
let ROW2_Y = road_y.[3]
let ROW3_Y = road_y.[2]
let ROW4_Y = road_y.[1]

let RIV1_Y = road_y.[9]
let RIV2_Y = road_y.[8]
let RIV3_Y = road_y.[7]
let RIV4_Y = road_y.[6]

let ROW1_Z = road_z.[4]
let ROW2_Z = road_z.[3]
let ROW3_Z = road_z.[2]
let ROW4_Z = road_z.[1]

let RIV1_Z = road_z.[9]
let RIV2_Z = road_z.[8]
let RIV3_Z = road_z.[7]
let RIV4_Z = road_z.[6]

//car speed constants
let mutable SPEED_ROW1 = -12.0f 
let mutable SPEED_ROW2 = -10.0f 
let mutable SPEED_ROW3 = 10.0f 
let mutable SPEED_ROW4 = 5.0f

//cars spawn limits constants
let mutable SPAWN_LIMIT_ROW1 = 10.0f
let mutable SPAWN_LIMIT_ROW2 = 30.0f
let mutable SPAWN_LIMIT_ROW3 = -20.0f
let mutable SPAWN_LIMIT_ROW4 = -10.0f

//river speed constants
let mutable SPEED_RIV1 = 6.0f
let mutable SPEED_RIV2 = -10.0f
let mutable SPEED_RIV3 = 7.0f
let mutable SPEED_RIV4 = -8.0f

//river spawn limits constants
let SPAWN_LIMIT_RIV1 = -28.0f
let SPAWN_LIMIT_RIV2 = 28.0f
let SPAWN_LIMIT_RIV3 = -32.0f
let SPAWN_LIMIT_RIV4 = 28.0f

// ****************************************************************************** //
//                                Update methods                                  //
// ****************************************************************************** //

let reset_speed() =
    SPEED_ROW1 <- -12.0f 
    SPEED_ROW2 <- -10.0f 
    SPEED_ROW3 <- 10.0f 
    SPEED_ROW4 <- 5.0f
    SPEED_RIV1 <- 6.0f
    SPEED_RIV2 <- -10.0f
    SPEED_RIV3 <- 7.0f
    SPEED_RIV4 <- -8.0f

let update_car_speed (mul:float32) =
    SPEED_ROW1 <- SPEED_ROW1 * mul
    SPEED_ROW2 <- SPEED_ROW2 * mul
    SPEED_ROW3 <- SPEED_ROW3 * mul
    SPEED_ROW4 <- SPEED_ROW4 * mul

let update_river_speed (mul:float32) =
    SPEED_RIV1 <- SPEED_RIV1 * mul
    SPEED_RIV2 <- SPEED_RIV2 * mul
    SPEED_RIV3 <- SPEED_RIV3 * mul
    SPEED_RIV4 <- SPEED_RIV4 * mul

let update_river_speed_hard (mul:float32, mul2: float32) =
    SPEED_RIV1 <- SPEED_RIV1 * mul2
    SPEED_RIV2 <- SPEED_RIV2 * mul
    SPEED_RIV3 <- SPEED_RIV3 * mul2
    SPEED_RIV4 <- SPEED_RIV4 * mul
